//
//  CSSMainViewController.swift
//  weibo28
//
//  Created by chushushan on 16/5/11.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CSSMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let cssTabbar = CSSTabBar()
        //设置代理对象
//        cssTabbar.cssDelegate = self
        
        
        cssTabbar.composeButtonClousre = { [weak self] in
//        print("中间加号的点击事件通过闭包传递到控制器里")
           
            self!.showComposeVC()
            
        }
        
        //使用kvc设置只读属性
        setValue(cssTabbar, forKey: "tabBar")

        //添加子控制的两种方式
        //1.viewControllers是把子控制器放到一个数组里
        //2.childViewControllers
        
     addChildViewController(CSSHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(CSSMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(CSSDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(CSSProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
        
        
       
    }
    
    func addChildViewController(childController: UIViewController, title: String, imageName: String) {
        
        childController.tabBarItem.title = title
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(14)], forState: .Normal)
        
        let nav = UINavigationController(rootViewController: childController)
        childController.navigationItem.title = title
        addChildViewController(nav)
        
    }
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
      
    }
    

 
    //进入发微博界面
    private func showComposeVC() {
    
        let composeVc = CSSComposeViewController()
        
        let composeNav = UINavigationController(rootViewController: composeVc)
        
        presentViewController(composeNav, animated: true, completion: nil)
        
        
    }
    
    
    
    

    
    
    
}




//extension CSSMainViewController: CSSTabBarDelegate {
//    
//    func didSelectedComposeButton() {
//        
//        print("我是代理")
//    }
//}
